#Main with covariates
main_lm_c1 <- lm_robust(message_main ~ factor(frame) + party_final_analysis + birth_year + female + income_scale + education + foreigntreat + racetreat, data = data)
main_lm_c2 <- lm_robust(message_main ~ factor(frame) + party_final_analysis + birth_year + female + income_scale + white + black + education + weather_shock + heat_shock + thermom_black + thermom_othercountry + foreigntreat + racetreat + c_out_orient_index + travel_gs, data = data)

main_lm_c1_dems <- lm_robust(message_main ~ factor(frame) + birth_year + female + income_scale + education + foreigntreat + racetreat, data = dems)
main_lm_c1_reps <- lm_robust(message_main ~ factor(frame) + birth_year + female + income_scale + education + foreigntreat + racetreat, data = reps)

main_lm_c2_dems <- lm_robust(message_main ~ factor(frame) + birth_year + female + income_scale + white + black + education + weather_shock + heat_shock + thermom_black + thermom_othercountry + foreigntreat + racetreat + c_out_orient_index + travel_gs, data = dems)
main_lm_c2_reps <- lm_robust(message_main ~ factor(frame) + birth_year + female + income_scale + white + black + education + weather_shock + heat_shock + thermom_black + thermom_othercountry + foreigntreat + racetreat + c_out_orient_index + travel_gs, data = reps)


models <- list(main_lm_c1, main_lm_c2, main_lm_c1_dems, main_lm_c2_dems,
               main_lm_c1_reps, main_lm_c2_reps)

tab5 <- texreg(models,
               custom.model.names = c("Covariates 1", "Covariates 2", "Dem Covariates 1", "Dem Covariates 2", "Rep Covariates 1", "Rep Covariates 2"),
               custom.coef.map = list("factor(frame)blame" = "Climate Justice",
                                      "factor(frame)global" = "Global Solidarity",
                                      "factor(frame)none" = "Appeal Only",
                                      "party_final_analysisRepublican" = "Republican Party",
                                      "party_final_analysisOther" = "Other Party",
                                      "birth_year" = 'Birth Year', 'female' = 'Female', 'income_scale' = 'Income',
                                      'white' = 'White', 'black' = 'Black', 'education' = 'Education',
                                      'weather_shock' = 'Weather Shock', 'heat_shock' = 'Heat Shock',
                                      'racetreat' = 'Race Treatment', 'foreigntreat' = 'Foreign Treatment', 'thermom_black' = 'Attitudes Black',
                                      'thermom_othercountry' = 'Attitudes Other Country', 'travel_gs' = 'Travel Global South',
                                      'c_out_orient_index' = 'Outward Orientation',
                                      '(Intercept)' = 'Constant'),
               caption = "Effect of climate emissions frames on Aid Support Index, with covariates",
               label = "tab:main.controls",
               include.rmse = FALSE,
               include.constant = TRUE, # Ensure constant is included
               include.ci = FALSE,
               stars = c(0.01, 0.05, 0.1),
               float.pos = "h")
tab5
writeLines(tab5, "MessagingFigsR/app_covars_main_RR.tex")

unique_variables <- unique(unlist(lapply(models, function(mod) grep("^factor\\(frame\\)", names(coef(mod)), value = TRUE))))

# Extract the coefficients and standard errors
results <- extract_coefficients(models, unique_variables)
results <- na.omit(results)

results$model <- c('cov1 j','cov1 s','cov2 j','cov2 s','d cov1 j','d cov1 s','d cov2 j','d cov2 s',
                   'r cov1 j','r cov1 s','r cov2 j','r cov2 s')
results$model <- factor(results$model, levels = c('cov1 s','cov2 s','cov1 j','cov2 j','d cov1 s','d cov2 s','d cov1 j','d cov2 j',
                                                  'r cov1 s','r cov2 s','r cov1 j','r cov2 j'))
results$column_set <- c('All','All','All','All',
                        'Democrats','Democrats','Democrats','Democrats','Republicans','Republicans','Republicans','Republicans')
results$column_set <- factor(results$column_set, levels = c("All", "Democrats", "Republicans"))  
results$coefficients <- as.numeric(results$coefficients)
results$standard_errors <- as.numeric(results$standard_errors)

x_labels <- c("cov1 s" = "Solidarity", 
              "cov2 s" = "Solidarity*", 
              "cov1 j" = "Justice",
              "cov2 j" = "Justice*",
              "d cov1 s" = "Solidarity",
              "d cov2 s" = "Solidarity*",
              "d cov1 j" = "Justice",
              "d cov2 j" = "Justice*",
              "r cov1 s" = "Solidarity",
              "r cov2 s" = "Solidarity*",
              "r cov1 j" = "Justice",
              "r cov2 j" = "Justice*")

# Plot the results
plot_results(results, x_labels, "Estimated Effect of climate emissions frames on Aid Support Index", c("All" = 'purple3', 'Democrats'= 'blue3', 'Republicans' = 'red3'), 
             "MessagingFigsR/app_covars_main_RR.png", "column_set")


#Donations
sec_lm_c1 <- lm_robust(c_donate_1 ~ factor(frame) + party_final_analysis + birth_year + female + income_scale + education + foreigntreat + racetreat, data = data)
sec_lm_c2 <- lm_robust(c_donate_1 ~ factor(frame) + party_final_analysis + birth_year + female + income_scale + white + black + education + weather_shock + heat_shock + thermom_black + thermom_othercountry + foreigntreat + racetreat + c_out_orient_index + travel_gs, data = data)

#regression analysis by party
sec_lm_c1_dems <- lm_robust(c_donate_1 ~ factor(frame) + birth_year + female + income_scale + education + foreigntreat + racetreat, data = dems)
sec_lm_c1_reps <- lm_robust(c_donate_1 ~ factor(frame) + birth_year + female + income_scale + education + foreigntreat + racetreat, data = reps)

sec_lm_c2_dems <- lm_robust(c_donate_1 ~ factor(frame) + birth_year + female + income_scale + white + black + education + weather_shock + heat_shock + thermom_black + thermom_othercountry + foreigntreat + racetreat + c_out_orient_index + travel_gs, data = dems)
sec_lm_c2_reps <- lm_robust(c_donate_1 ~ factor(frame) + birth_year + female + income_scale + white + black + education + weather_shock + heat_shock + thermom_black + thermom_othercountry + foreigntreat + racetreat + c_out_orient_index + travel_gs, data = reps)

models <- list(sec_lm_c1, sec_lm_c2, sec_lm_c1_dems, sec_lm_c2_dems,
               sec_lm_c1_reps, sec_lm_c2_reps)

tab6 <- texreg(models,
               custom.model.names = c("Covariates 1", "Covariates 2", "Dem Covariates 1", "Dem Covariates 2", "Rep Covariates 1", "Rep Covariates 2"),
               custom.coef.map = list("factor(frame)blame" = "Climate Justice",
                                      "factor(frame)global" = "Global Solidarity",
                                      "factor(frame)none" = "Appeal Only",
                                      "party_final_analysisRepublican" = "Republican Party",
                                      "party_final_analysisOther" = "Other Party",
                                      "birth_year" = 'Birth Year', 'female' = 'Female', 'income_scale' = 'Income',
                                      'white' = 'White', 'black' = 'Black', 'education' = 'Education',
                                      'weather_shock' = 'Weather Shock', 'heat_shock' = 'Heat Shock',
                                      'racetreat' = 'Race Treatment', 'foreigntreat' = 'Foreign Treatment', 'thermom_black' = 'Attitudes Black',
                                      'thermom_othercountry' = 'Attitudes Other Country', 'travel_gs' = 'Travel Global South',
                                      'c_out_orient_index' = 'Outward Orientation',
                                      '(Intercept)' = 'Constant'),
               caption = "Effect of climate emissions frames on personal donation attitudes, with covariates",
               label = "tab:sec.controls",
               include.rmse = FALSE,
               include.constant = TRUE, # Ensure constant is included
               include.ci = FALSE,
               stars = c(0.01, 0.05, 0.1),
               float.pos = "h")
tab6
writeLines(tab6, "MessagingFigsR/app_covars_sec_RR.tex")

# Get the unique variables across all models
unique_variables <- unique(unlist(lapply(models, function(mod) grep("^factor\\(frame\\)", names(coef(mod)), value = TRUE))))

# Extract the coefficients and standard errors
results <- extract_coefficients(models, unique_variables)
results <- na.omit(results)

results$model <- c('cov1 j','cov1 s','cov2 j','cov2 s','d cov1 j','d cov1 s','d cov2 j','d cov2 s',
                   'r cov1 j','r cov1 s','r cov2 j','r cov2 s')
results$model <- factor(results$model, levels = c('cov1 s','cov2 s','cov1 j','cov2 j','d cov1 s','d cov2 s','d cov1 j','d cov2 j',
                                                  'r cov1 s','r cov2 s','r cov1 j','r cov2 j'))
results$column_set <- c('All','All','All','All',
                        'Democrats','Democrats','Democrats','Democrats','Republicans','Republicans','Republicans','Republicans')
results$column_set <- factor(results$column_set, levels = c("All", "Democrats", "Republicans"))  

results$coefficients <- as.numeric(results$coefficients)
results$standard_errors <- as.numeric(results$standard_errors)

x_labels <- c("cov1 s" = "Solidarity", 
              "cov2 s" = "Solidarity*", 
              "cov1 j" = "Justice",
              "cov2 j" = "Justice*",
              "d cov1 s" = "Solidarity",
              "d cov2 s" = "Solidarity*",
              "d cov1 j" = "Justice",
              "d cov2 j" = "Justice*",
              "r cov1 s" = "Solidarity",
              "r cov2 s" = "Solidarity*",
              "r cov1 j" = "Justice",
              "r cov2 j" = "Justice*")

# Plot the results
plot_results(results, x_labels, "Estimated Effect of climate emissions frames on Personal Donations", c("All" = 'purple3', 'Democrats'= 'blue3', 'Republicans' = 'red3'), 
             "MessagingFigsR/app_covars_sec_RR.png", "column_set")

# WITH INTERACTION TERMS
data_noOther <- data[data$party_final_analysis != 'Other',]
table(data_noOther$party_final_analysis)
main_lm_partyI <- lm_robust(message_main ~ factor(frame) + party_final_analysis*factor(frame), data = data_noOther)
sec_lm_partyI <- lm_robust(c_donate_1 ~ factor(frame) + party_final_analysis*factor(frame), data = data_noOther)

summary(main_lm_partyI)
summary(sec_lm_partyI)

tab6 <- texreg(list(main_lm_partyI, sec_lm_partyI),
               custom.model.names=c("Main Outcome", "Donations Outcome"),
               custom.coef.map = list("factor(frame)blame" = "Climate Justice",
                                      "factor(frame)global" = "Global Solidarity",
                                      "factor(frame)none" = "Appeal Only",
                                      "party_final_analysisRepublican" = "Republican Party",
                                      "party_final_analysisOther" = "Other Party",
                                      "factor(frame)blame:party_final_analysisRepublican" = 'Interaction: Justice Republican',
                                      "factor(frame)blame:party_final_analysisOther" ='Interaction: Justice Other',
                                      "factor(frame)global:party_final_analysisRepublican"='Interaction: Solidarity Republican',
                                      "factor(frame)global:party_final_analysisOther" = 'Interaction: Solidarity Other',
                                      '(Intercept)' = 'Constant'),
               caption="Estimated Effect of climate emissions frames on Aid Support Index and personal donation attitudes with party interaction term",
               label="tab:party.interaction",
               include.rmse = FALSE,
               include.ci = FALSE,
               stars = c(0.01, 0.05, 0.1),
               float.pos = "h")
tab6
writeLines(tab6,"MessagingFigsR/app_party_int_RR.tex")


# Index split into two separate outcomes
# just president and just US help

pres_lm <- lm_robust(president ~ factor(frame), data = data)
pres_lm_d <- lm_robust(president ~ factor(frame), data = dems)
pres_lm_r <- lm_robust(president ~ factor(frame), data = reps)

help_lm <- lm_robust(us_help ~ factor(frame), data = data)
help_lm_d <- lm_robust(us_help ~ factor(frame), data = dems)
help_lm_r <- lm_robust(us_help ~ factor(frame), data = reps)

pres <- texreg(list(pres_lm, pres_lm_d, pres_lm_r),
       custom.model.names=c("Presidential", "Presidential D", "Presidential R"),
       custom.coef.map = list("factor(frame)blame" = "Climate Justice",
                              "factor(frame)global" = "Global Solidarity",
                              "factor(frame)none" = "Appeal Only",'(Intercept)' = 'Constant'
       ),
       
       caption="Estimated Effect of climate emissions frames on Presidential Pledge Donations (part of Aid Support Index)",
       label="tab:pres.only",
       include.rmse = FALSE,
       include.ci = FALSE,
       stars = c(0.01, 0.05, 0.1),
       float.pos = "h")
pres
writeLines(pres,"MessagingFigsR/app_pres_only_RR.tex")


help <- texreg(list(help_lm, help_lm_d, help_lm_r),
       custom.model.names=c("US Aid", "US Aid D", "US Aid R"),
       custom.coef.map = list("factor(frame)blame" = "Climate Justice",
                              "factor(frame)global" = "Global Solidarity",
                              "factor(frame)none" = "Appeal Only",'(Intercept)' = 'Constant'
       ),
       
       caption="Estimated Effect of climate emissions frames on support for US Assistance (part of Aid Support Index)",
       label="tab:help.only",
       include.rmse = FALSE,
       include.ci = FALSE,
       stars = c(0.01, 0.05, 0.1),
       float.pos = "h")
help
writeLines(help,"MessagingFigsR/app_usaid_only_RR.tex")

##WHITE ONLY
# main reg
white <- subset(data, white == 1)
black <- subset(data, black == 1)
demsW <- subset(white, party_final_analysis == 'Democrat')
repsW <- subset(white, party_final_analysis == 'Republican')
demsB <- subset(black, party_final_analysis == 'Democrat')
repsB <- subset(black, party_final_analysis == 'Republican')

white_lm <- lm_robust(message_main ~ factor(frame), data = white)
white_lm_dems <- lm_robust(message_main ~ factor(frame), data = demsW)
white_lm_reps <- lm_robust(message_main ~ factor(frame), data = repsW)

black_lm <- lm_robust(message_main ~ factor(frame), data = black)
black_lm_dems <- lm_robust(message_main ~ factor(frame), data = demsB)
black_lm_reps <- lm_robust(message_main ~ factor(frame), data = repsB)

white <- texreg(list(white_lm, white_lm_dems,
                   white_lm_reps),
              custom.model.names=c("White", "Democrats", "Republicans"),
              custom.coef.map = list("factor(frame)blame" = "Climate Justice",
                                     "factor(frame)global" = "Global Solidarity",
                                     "factor(frame)none" = "Appeal Only", '(Intercept)' = 'Constant'),
              
              caption="Effect of climate emissions frames on Aid Support Index, white respondents",
              label="tab:main.white",
              include.rmse = FALSE,
              include.ci = FALSE,
              stars = c(0.01, 0.05, 0.1),
              float.pos = "h")
white
writeLines(white,"MessagingFigsR/app_main_white_RR.tex")


black <- texreg(list(black_lm, black_lm_dems,
                   black_lm_reps),
              custom.model.names=c("Black", "Democrats", "Republicans"),
              custom.coef.map = list("factor(frame)blame" = "Climate Justice",
                                     "factor(frame)global" = "Global Solidarity",
                                     "factor(frame)none" = "Appeal Only", '(Intercept)' = 'Constant'),
              
              caption="Effect of climate emissions frames on Aid Support Index, black respondents",
              label="tab:main.black",
              include.rmse = FALSE,
              include.ci = FALSE,
              stars = c(0.01, 0.05, 0.1),
              float.pos = "h")
black
writeLines(black,"MessagingFigsR/app_main_black_RR.tex")


## DATA QUALITY METRICS

process_data_main <- function(data, dems, reps, data_name, name) {
  # Initial releveling and model fitting
  main_lm <- lm_robust(message_main ~ factor(frame), data = data)
  main_lm_covars <- lm_robust(message_main ~ factor(frame) + party_final_analysis + birth_year + female + income_scale + education + foreigntreat + racetreat, data = data)
  
  main_lm_dems <- lm_robust(message_main ~ factor(frame), data = dems)
  main_lm_reps <- lm_robust(message_main ~ factor(frame), data = reps)
  
  # Collect models for table creation
  models <- list(main_lm, main_lm_covars, main_lm_dems, main_lm_reps)
  
  # Create regression table
  tab <- texreg(models, 
                custom.model.names = c("Main", "Covariate", "Democrats", "Republicans"),
                custom.coef.map = list("factor(frame)blame" = "Climate Justice",
                                       "factor(frame)global" = "Global Solidarity",
                                       "factor(frame)none" = "Appeal Only",
                                       "party_final_analysisRepublican" = "Republican Party",
                                       "party_final_analysisOther" = "Other Party",
                                       "birth_year" = "Birth Year", 'female' = 'Female',
                                       'white' = 'White', 'black' = 'Black', 'education' = 'Education',
                                       'weather_shock' = 'Weather Shock', 'heat_shock' = 'Heat Shock',
                                       'racetreat' = 'Race Treatment', 'income_scale' = 'Income','foreigntreat' = 'Foreign Treatment',
                                       'c_out_orient_index' = 'Outward Orientation', '(Intercept)' = 'Constant'),
                caption = paste("Effect of climate emissions frames on Aid Support Index,",name),
                label = paste0("tab:main_", data_name),
                include.rmse = FALSE,
                include.ci = FALSE,
                stars = c(0.01, 0.05, 0.1),
                float.pos = "h")
  paste('Main',data_name)
  tab
  # Save regression table
  writeLines(tab, paste0("MessagingFigsR/app_main_", data_name, ".tex"))
  return(models)
}

process_data_sec <- function(data, dems, reps, data_name, name) {
  main_lm <- lm_robust(c_donate_1 ~ factor(frame), data = data)
  main_lm_covars <- lm_robust(c_donate_1 ~ factor(frame) + party_final_analysis + birth_year + female + income_scale + education + foreigntreat + racetreat, data = data)
  
  main_lm_dems <- lm_robust(c_donate_1 ~ factor(frame), data = dems)
  main_lm_reps <- lm_robust(c_donate_1 ~ factor(frame), data = reps)
  
  # Collect models for table creation
  models <- list(main_lm, main_lm_covars, main_lm_dems, main_lm_reps)
  
  # Create regression table
  tab <- texreg(models, 
                custom.model.names = c("Main", "Covariate", "Democrats", "Republicans"),
                custom.coef.map = list("factor(frame)blame" = "Climate Justice",
                                       "factor(frame)global" = "Global Solidarity",
                                       "factor(frame)none" = "Appeal Only",
                                       "party_final_analysisRepublican" = "Republican Party",
                                       "party_final_analysisOther" = "Other Party",
                                       "birth_year" = "Birth Year", 'female' = 'Female',
                                       'white' = 'White', 'black' = 'Black', 'education' = 'Education',
                                       'weather_shock' = 'Weather Shock', 'heat_shock' = 'Heat Shock',
                                       'racetreat' = 'Race Treatment', 'income_scale' = 'Income','foreigntreat' = 'Foreign Treatment',
                                       'c_out_orient_index' = 'Outward Orientation', '(Intercept)' = 'Constant'),
                caption = paste("Effect of climate emissions frames on personal donation attitudes,", name),
                include.rmse = FALSE,
                include.ci = FALSE,
                stars = c(0.01, 0.05, 0.1),
                float.pos = "h")
  paste('Sec',data_name)
  tab
  # Save regression table
  writeLines(tab, paste0("MessagingFigsR/app_sec_", data_name, ".tex"))
  
  return(models)
}

data_quality_attn <- data[data$Q1 == 'The Drudge Report,ABC News website',] #& 
                           # data$f_attcheck_ad == 'Somewhat agree',] #&
data_quality_attn_dems <- dems[dems$Q1 == 'The Drudge Report,ABC News website',]# & 
                           # dems$f_attcheck_ad == 'Somewhat agree',]
data_quality_attn_reps <- reps[reps$Q1 == 'The Drudge Report,ABC News website',]# & 
                         #   reps$f_attcheck_ad == 'Somewhat agree',]
#

data_quality_prog <- data[data$Progress == 100,]
data_quality_prog_dems <- dems[dems$Progress == 100,]
data_quality_prog_reps <- reps[reps$Progress == 100,]

# Then, filter based on 'Duration' being more than 1/3 of the median
data_quality_median <- data[data$`Duration (in seconds)` > (median(data$`Duration (in seconds)`) / 3), ]
data_quality_median_dems <- dems[dems$`Duration (in seconds)` > (median(dems$`Duration (in seconds)`) / 3), ]
data_quality_median_reps <- reps[reps$`Duration (in seconds)` > (median(reps$`Duration (in seconds)`) / 3), ]

# Finally, filter out rows where 'c_moral_ad', 'c_toomuchtalk_ad', 'c_moresimilar_ad', 'c_worried_ad' are equal
data_quality_battery <- data[!(data$c_moral_ad == data$c_toomuchtalk_ad &
                                 data$c_toomuchtalk_ad == data$c_moresimilar_ad &
                                 data$c_moresimilar_ad == data$c_worried_ad), ]
data_quality_battery_dems <- dems[!(dems$c_moral_ad == dems$c_toomuchtalk_ad &
                                      dems$c_toomuchtalk_ad == dems$c_moresimilar_ad &
                                      dems$c_moresimilar_ad == dems$c_worried_ad), ]
data_quality_battery_reps <- reps[!(reps$c_moral_ad == reps$c_toomuchtalk_ad &
                                      reps$c_toomuchtalk_ad == reps$c_moresimilar_ad &
                                      reps$c_moresimilar_ad == reps$c_worried_ad), ]

process_data_main(data_quality_attn, data_quality_attn_dems, data_quality_attn_reps, 'attention_check', 'Both Attention Checks')
process_data_sec(data_quality_attn, data_quality_attn_dems, data_quality_attn_reps, 'attention_check', 'Both Attention Checks')

process_data_main(data_quality_battery,data_quality_battery_dems,data_quality_battery_reps, 'straightline', 'No Straightline')
process_data_sec(data_quality_battery,data_quality_battery_dems,data_quality_battery_reps, 'straightline', 'No Straightline')

process_data_main(data_quality_median,data_quality_median_dems,data_quality_median_reps, 'median', 'Not below 1/3 Median Response Time')
process_data_sec(data_quality_median,data_quality_median_dems,data_quality_median_reps, 'median', 'Not below 1/3 Median Response Time')

process_data_main(data_quality_prog,data_quality_prog_dems,data_quality_prog_reps, 'progress', 'Completed Survey')
process_data_sec(data_quality_prog,data_quality_prog_dems,data_quality_prog_reps, 'progress', 'Completed Survey')

# Outcomes with solidarity base
# Relevel the frame variable
data$frame_rl <- relevel(data$frame, ref = "global")
dems$frame_rl <- relevel(dems$frame, ref = "global")
reps$frame_rl <- relevel(reps$frame, ref = "global")

# Main regression models
main_lm <- lm_robust(message_main ~ factor(frame_rl), data = data)
main_lm_dems <- lm_robust(message_main ~ factor(frame_rl), data = dems)
main_lm_reps <- lm_robust(message_main ~ factor(frame_rl), data = reps)

# LaTeX table for main models only
tab <- texreg(list(main_lm, main_lm_dems, main_lm_reps),
              custom.model.names = c("Main", "Democrats", "Republicans"),
              custom.coef.map = list("factor(frame_rl)blame" = "Climate Justice",
                                     "factor(frame_rl)global" = "Global Solidarity",
                                     "factor(frame_rl)none" = "Appeal Only", '(Intercept)' = 'Constant'),
              caption = "Effect of climate emissions frames on Aid Support Index, compared to Global Solidarity Treatment",
              label = "tab:relevel.aid",
              include.rmse = FALSE,
              include.ci = FALSE,
              stars = c(0.01, 0.05, 0.1),
              float.pos = "h")
tab
writeLines(tab, "MessagingFigsR/app_main_solidarity_RR.tex")

# Main regression models without controls for private donations
sec_lm <- lm_robust(c_donate_1 ~ factor(frame_rl), data = data)
sec_lm_dems <- lm_robust(c_donate_1 ~ factor(frame_rl), data = dems)
sec_lm_reps <- lm_robust(c_donate_1 ~ factor(frame_rl), data = reps)

# LaTeX table for main models only
tab2 <- texreg(list(sec_lm, sec_lm_dems, sec_lm_reps),
               custom.model.names = c("Main", "Democrats", "Republicans"),
               custom.coef.map = list("factor(frame_rl)blame" = "Climate Justice",
                                      "factor(frame_rl)global" = "Global Solidarity",
                                      "factor(frame_rl)none" = "Appeal Only", '(Intercept)' = 'Constant'),
               caption = "Effect of climate emissions frames on personal donation attitudes, compared to Global Solidarity Treatment",
               label = "tab:relevel.personal.donation",
               include.rmse = FALSE,
               include.ci = FALSE,
               stars = c(0.01, 0.05, 0.1),
               float.pos = "h")
tab2
writeLines(tab2, "MessagingFigsR/app_sec_solidarity_RR.tex")

#Thermom Q for H5
data$solidarity <- ifelse(data$frame == 'global',1,0)
main_lm_thermom <- lm_robust(message_main ~ solidarity + thermom_oc_index + thermom_oc_index*solidarity, data = data)
sec_lm_thermom <- lm_robust(c_donate_1 ~ solidarity + thermom_oc_index + thermom_oc_index*solidarity, data = data)
summary(main_lm_thermom)
tab4 <- texreg(list(main_lm_thermom,sec_lm_thermom),
               custom.model.names = c("Main", "Secondary"),
               custom.coef.map = list("factor(frame)blame" = "Climate Justice",
                                      "factor(frame)global" = "Global Solidarity",
                                      "factor(frame)none" = "Appeal Only",
                                      'solidarity' = 'Global Solidarity',
                                      "thermom_oc_index" = "Thermom Other Country", 
                                      "factor(frame)blame:thermom_oc_index" = 'Interaction: Justice',  
                                      "solidarity:thermom_oc_index" = 'Interaction: Solidarity', '(Intercept)' = 'Constant'),
               caption = "Effect of climate treatment on personal donation attitudes",
               label = "tab:personal.donation",
               include.rmse = FALSE,
               include.ci = FALSE,
               stars = c(0.01, 0.05, 0.1),
               float.pos = "h")
tab4
writeLines(tab4, "MessagingFigsR/app_H5_reg_RR.tex")


